package com.freight.system.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.freight.common.core.domain.R;
import com.freight.system.service.impl.QiniuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用请求处理
 * 
 */
@RestController
@RequestMapping("/oss")
public class OssController
{

    @Autowired
    QiniuService qiniuService;

    /***
     * 获取七牛云上传凭证
     * @return
     */
    @RequestMapping("/getUploadToken")
    public R<Map<String,String>> getUploadToken(){
       if(qiniuService.getUploadToken()==null){
           return R.fail("获取上传凭证失败");
       }
       String token=qiniuService.getUploadToken();
       String fileName=IdWorker.get32UUID();
       Map<String,String> data=new HashMap<>();
       data.put("token",token);
       data.put("fileName",fileName);
       return R.ok(data);
    }


}
